<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="仓库">
              <j-dict-select-tag
                placeholder="请选择仓库"
                v-model="queryParam.warehouseCode"
                dictCode="wms_warehouse,warehouse_name,warehouse_code"
              />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="物料名称">
              <a-input placeholder="请输入物料名称" v-model="queryParam.materialName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="物料编码">
              <a-input placeholder="请输入物料编码" v-model="queryParam.materialCode"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item label="入库日期">
              <j-date
                :show-time="true"
                date-format="YYYY-MM-DD"
                placeholder="请选择开始时间"
                class="query-group-cust"
                v-model="queryParam.entryDateBegin"></j-date>
              <span class="query-group-split-cust"></span>
              <j-date
                :show-time="true"
                date-format="YYYY-MM-DD"
                placeholder="请选择结束时间"
                class="query-group-cust"
                v-model="queryParam.entryDateEnd"></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('入库记录')">导出</a-button>
      <a-button type="primary" icon="printer" @click="handlePrint">标签打印</a-button>
      <a-button type="primary" icon="printer" @click="handleLabelPrint">标签补打</a-button>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        <span style="float:right;">
          <a-popover title="自定义列" trigger="click" placement="leftBottom">
            <template slot="content">
              <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
                <a-row style="width: 400px">
                  <template v-for="(item,index) in defColumns">
                    <template v-if="item.key!=='rowIndex'&& item.dataIndex!=='action'">
                        <a-col :span="12"><a-checkbox :value="item.dataIndex"><j-ellipsis :value="item.title" :length="10"></j-ellipsis></a-checkbox></a-col>
                    </template>
                  </template>
                </a-row>
              </a-checkbox-group>
            </template>
            <a><a-icon type="setting" />设置</a >
          </a-popover>
        </span>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="inbound_order_item_id"
        class="j-table-force-nowrap1"
        :scroll="{ x: true }"
        :columns="computedColumns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        @change="handleTableChange"
      >
        <template slot="remark" slot-scope="text, record">
          <div v-if="record.creatorRemark">制单人:{{ record.creatorRemark }}</div>
          <div v-if="record.handlerRemark">经办人:{{ record.handlerRemark }}</div>
          <div v-if="record.inspectorRemark">检验人:{{ record.inspectorRemark }}</div>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleDetail(record)">详情</a>
          <a-divider type="vertical" />
          <a @click="handleRevoke(record)" style="color: #ff4d4f">撤销</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
              <a-menu slot="overlay">
                <a-menu-item>
                  <a @click="printPreview(record)">单据打印</a>
                </a-menu-item>
                <a-menu-item>
                  <a v-if="procurementType.includes(record.entryType)" @click="handleStoreDetail(record)">附件查看</a>
                </a-menu-item>
              </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>

    <inbound-record-new-modal ref="modalForm" @ok="modalFormOk" />
    <inbound-record-label-print-modal ref="labelPrintModalForm" @ok="modalFormOk" />
    <inbound-store-modal ref="storeModalForm" @ok="modalFormOk" />
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import InboundRecordNewModal from './modules/InboundRecordNewModal.vue'
import '@/assets/less/TableExpand.less'
import dayjs from 'dayjs'
import { getAction, putAction } from '@api/manage'
import InboundRecordLabelPrintModal from './modules/InboundRecordLabelPrintModal.vue'
import { JVXETypes } from '@/components/jeecg/JVxeTable'
import InboundStoreModal from './modules/InboundStoreModal.vue'

export default {
  name: 'InboundRecordList',
  mixins: [JeecgListMixin],
  components: {
    InboundRecordLabelPrintModal,
    InboundRecordNewModal,
    InboundStoreModal,
  },
  data() {
    return {
      description: '入库记录管理页面',
      activeKey: 'notGenerated',
      // 表头
      columns1: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          fixed: 'left',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '入库记录单号',
          align: 'center',
          dataIndex: 'recordNumber',
          fixed: 'left',
        },
        {
          title: '入库类型',
          align: 'center',
          dataIndex: 'entryType_dictText',
          fixed: 'left',
        },
        {
          title: '单据号',
          align: 'center',
          dataIndex: 'documentNumber',
          fixed: 'left',
        },
        /*
        {
          title: '入库单号',
          align: 'center',
          dataIndex: 'entryNumber',
          fixed: 'left'
        },
        */
        {
          title: '客户物料编码',
          align: 'center',
          dataIndex: 'customerMaterialCode',
        },
        {
          title: '物料编码',
          align: 'center',
          dataIndex: 'materialCode',
        },
        {
          title: '物料名称',
          align: 'center',
          dataIndex: 'materialName',
        },
        {
          title: '规格型号',
          align: 'center',
          dataIndex: 'specificationModel',
        },
        // {
        //   title: '物料描述',
        //   align: 'center',
        //   dataIndex: 'materialDesc'
        // },
        {
          title: '单位',
          align: 'center',
          dataIndex: 'unit_dictText',
        },
        {
          title: '数量',
          align: 'center',
          dataIndex: 'quantity',
        },
        {
          title: '辅单位',
          align: 'center',
          dataIndex: 'secondaryUnit_dictText',
        },
        {
          title: '辅数量',
          align: 'center',
          dataIndex: 'secondaryQuantity',
        },
        {
          title: '宝洁订单号',
          align: 'center',
          dataIndex: 'pgOrderNumber',
        },
        {
          title: '订单编号',
          align: 'center',
          dataIndex: 'orderNumber',
        },
        {
          title: '生产车间',
          align: 'center',
          dataIndex: 'productionShop_dictText',
        },
        {
          title: '生产日期',
          align: 'center',
          dataIndex: 'productionDate',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '保质期（天）',
          align: 'center',
          dataIndex: 'shelfLife',
        },
        {
          title: '限用日期',
          align: 'center',
          dataIndex: 'expirationDate',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '批次号',
          align: 'center',
          dataIndex: 'batchNumber',
        },
        {
          title: '物料批号',
          align: 'center',
          dataIndex: 'materialBatchNumber',
        },
        {
          title: '储位',
          align: 'center',
          dataIndex: 'storageLocation_dictText',
        },
        {
          title: '入库日期',
          align: 'center',
          dataIndex: 'entryDate',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '库龄（天）',
          align: 'center',
          dataIndex: 'inventoryAge',
        },
        {
          title: '质检状态',
          align: 'center',
          dataIndex: 'qualityInspectionStatus_dictText',
        },
        {
          title: '供应商名称',
          align: 'center',
          dataIndex: 'supplierName',
        },
        {
          title: '宝洁采购订单号',
          align: 'center',
          dataIndex: 'pgPurchaseOrderNumber',
        },
        {
          title: '宝洁供应商编号',
          align: 'center',
          dataIndex: 'pgSupplierCode',
        },
        {
          title: '宝洁供应商',
          align: 'center',
          dataIndex: 'pgSupplierCode_dictText',
        },
        {
          title: '客户名称',
          align: 'center',
          dataIndex: 'customerName',
        },
        {
          title: '物料分类1',
          align: 'center',
          dataIndex: 'materialClassify_dictText',
        },
        {
          title: '物料分类2',
          align: 'center',
          dataIndex: 'brand_dictText',
        },
        {
          title: '更新时间',
          align: 'center',
          dataIndex: 'updateTime',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '制单人',
          align: 'center',
          dataIndex: 'creator_dictText',
        },
        {
          title: '制单部门',
          align: 'center',
          dataIndex: 'creatorDeptCode_dictText',
        },
        {
          title: '制单日期',
          align: 'center',
          dataIndex: 'creationDate',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        // {
        //   title:'制单人备注',
        //   align:"center",
        //   dataIndex: 'creatorRemark'
        // },
        {
          title: '经办人',
          align: 'center',
          dataIndex: 'createBy_dictText',
        },
        {
          title: '经办部门',
          align: 'center',
          dataIndex: 'sysOrgCode_dictText',
        },
        {
          title: '经办日期',
          align: 'center',
          dataIndex: 'createTime',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        // {
        //   title:'经办人备注',
        //   align:"center",
        //   dataIndex: 'handlerRemark'
        // },
        {
          title: '检验标准',
          align: 'center',
          dataIndex: 'inspectionStandard',
        },
        {
          title: '抽检数量',
          align: 'center',
          dataIndex: 'samplingQuantity',
        },
        {
          title: '检验结果',
          align: 'center',
          dataIndex: 'inspectionResult',
        },
        {
          title: '检验人',
          align: 'center',
          dataIndex: 'inspector_dictText',
        },
        {
          title: '检验部门',
          align: 'center',
          dataIndex: 'inspectionDeptCode_dictText',
        },
        {
          title: '检验日期',
          align: 'center',
          dataIndex: 'inspectionDate',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        // 备注
        // 制单人备注：
        // 经办人备注：
        // 检验人备注：
        {
          title: '备注',
          align: 'center',
          dataIndex: 'remark',
          scopedSlots: { customRender: 'remark' },
        },
        // {
        //   title:'检验人备注',
        //   align:"center",
        //   dataIndex: 'inspectorRemark'
        // },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 80,
          scopedSlots: { customRender: 'action' },
        },
      ],
      columns: [
        {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            fixed: 'left',
            customRender: function (t, r, index) {
                return parseInt(index) + 1;
            },
        },
        {
            title: '入库记录单号',
            align: 'center',
            dataIndex: 'recordNumber',
            fixed: 'left',
            sorter: (a, b) => {
                const valA = a.recordNumber || '';
                const valB = b.recordNumber || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '入库类型',
            align: 'center',
            dataIndex: 'entryType_dictText',
            fixed: 'left',
            sorter: (a, b) => {
                const valA = a.entryType_dictText || '';
                const valB = b.entryType_dictText || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '单据号',
            align: 'center',
            dataIndex: 'documentNumber',
            fixed: 'left',
            sorter: (a, b) => {
                const valA = a.documentNumber || '';
                const valB = b.documentNumber || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '客户物料编码',
            align: 'center',
            dataIndex: 'customerMaterialCode',
            sorter: (a, b) => {
                const valA = a.customerMaterialCode || '';
                const valB = b.customerMaterialCode || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '物料编码',
            align: 'center',
            dataIndex: 'materialCode',
            sorter: (a, b) => {
                const valA = a.materialCode || '';
                const valB = b.materialCode || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '物料名称',
            align: 'center',
            dataIndex: 'materialName',
            sorter: (a, b) => {
                const valA = a.materialName || '';
                const valB = b.materialName || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '规格型号',
            align: 'center',
            dataIndex: 'specificationModel',
            sorter: (a, b) => {
                const valA = a.specificationModel || '';
                const valB = b.specificationModel || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '单位',
            align: 'center',
            dataIndex: 'unit_dictText',
            sorter: (a, b) => {
                const valA = a.unit_dictText || '';
                const valB = b.unit_dictText || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '数量',
            align: 'center',
            dataIndex: 'quantity',
            sorter: (a, b) => {
                const valA = a.quantity;
                const valB = b.quantity;
                if (valA == null && valB == null) return 0;
                if (valA == null) return 1;
                if (valB == null) return -1;
                return Number(valA) - Number(valB);
            },
        },
        {
            title: '辅单位',
            align: 'center',
            dataIndex: 'secondaryUnit_dictText',
            sorter: (a, b) => {
                const valA = a.secondaryUnit_dictText || '';
                const valB = b.secondaryUnit_dictText || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '辅数量',
            align: 'center',
            dataIndex: 'secondaryQuantity',
            sorter: (a, b) => {
                const valA = a.secondaryQuantity;
                const valB = b.secondaryQuantity;
                if (valA == null && valB == null) return 0;
                if (valA == null) return 1;
                if (valB == null) return -1;
                return Number(valA) - Number(valB);
            },
        },
        {
            title: '宝洁订单号',
            align: 'center',
            dataIndex: 'pgOrderNumber',
            sorter: (a, b) => {
                const valA = a.pgOrderNumber || '';
                const valB = b.pgOrderNumber || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '订单编号',
            align: 'center',
            dataIndex: 'orderNumber',
            sorter: (a, b) => {
                const valA = a.orderNumber || '';
                const valB = b.orderNumber || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '生产车间',
            align: 'center',
            dataIndex: 'productionShop_dictText',
            sorter: (a, b) => {
                const valA = a.productionShop_dictText || '';
                const valB = b.productionShop_dictText || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '生产日期',
            align: 'center',
            dataIndex: 'productionDate',
            customRender: function (text) {
                return !text ? '' : text.length > 10 ? text.substr(0, 10) : text;
            },
            sorter: (a, b) => {
                const valA = a.productionDate || '';
                const valB = b.productionDate || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '保质期（天）',
            align: 'center',
            dataIndex: 'shelfLife',
            sorter: (a, b) => {
                const valA = a.shelfLife;
                const valB = b.shelfLife;
                if (valA == null && valB == null) return 0;
                if (valA == null) return 1;
                if (valB == null) return -1;
                return Number(valA) - Number(valB);
            },
        },
        {
            title: '限用日期',
            align: 'center',
            dataIndex: 'expirationDate',
            customRender: function (text) {
                return !text ? '' : text.length > 10 ? text.substr(0, 10) : text;
            },
            sorter: (a, b) => {
                const valA = a.expirationDate || '';
                const valB = b.expirationDate || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '批次号',
            align: 'center',
            dataIndex: 'batchNumber',
            sorter: (a, b) => {
                const valA = a.batchNumber || '';
                const valB = b.batchNumber || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '物料批号',
            align: 'center',
            dataIndex: 'materialBatchNumber',
            sorter: (a, b) => {
                const valA = a.materialBatchNumber || '';
                const valB = b.materialBatchNumber || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '储位',
            align: 'center',
            dataIndex: 'storageLocation_dictText',
            sorter: (a, b) => {
                const valA = a.storageLocation_dictText || '';
                const valB = b.storageLocation_dictText || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '入库日期',
            align: 'center',
            dataIndex: 'entryDate',
            customRender: function (text) {
                return !text ? '' : text.length > 10 ? text.substr(0, 10) : text;
            },
            sorter: (a, b) => {
                const valA = a.entryDate || '';
                const valB = b.entryDate || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '库龄（天）',
            align: 'center',
            dataIndex: 'inventoryAge',
            sorter: (a, b) => {
                const valA = a.inventoryAge;
                const valB = b.inventoryAge;
                if (valA == null && valB == null) return 0;
                if (valA == null) return 1;
                if (valB == null) return -1;
                return Number(valA) - Number(valB);
            },
        },
        {
            title: '质检状态',
            align: 'center',
            dataIndex: 'qualityInspectionStatus_dictText',
            sorter: (a, b) => {
                const valA = a.qualityInspectionStatus_dictText || '';
                const valB = b.qualityInspectionStatus_dictText || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '供应商名称',
            align: 'center',
            dataIndex: 'supplierName',
            sorter: (a, b) => {
                const valA = a.supplierName || '';
                const valB = b.supplierName || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '宝洁采购订单号',
            align: 'center',
            dataIndex: 'pgPurchaseOrderNumber',
            sorter: (a, b) => {
                const valA = a.pgPurchaseOrderNumber || '';
                const valB = b.pgPurchaseOrderNumber || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '宝洁供应商编号',
            align: 'center',
            dataIndex: 'pgSupplierCode',
            sorter: (a, b) => {
                const valA = a.pgSupplierCode || '';
                const valB = b.pgSupplierCode || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '宝洁供应商',
            align: 'center',
            dataIndex: 'pgSupplierCode_dictText',
            sorter: (a, b) => {
                const valA = a.pgSupplierCode_dictText || '';
                const valB = b.pgSupplierCode_dictText || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '客户名称',
            align: 'center',
            dataIndex: 'customerName',
            sorter: (a, b) => {
                const valA = a.customerName || '';
                const valB = b.customerName || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '物料分类1',
            align: 'center',
            dataIndex: 'materialClassify_dictText',
            sorter: (a, b) => {
                const valA = a.materialClassify_dictText || '';
                const valB = b.materialClassify_dictText || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '物料分类2',
            align: 'center',
            dataIndex: 'brand_dictText',
            sorter: (a, b) => {
                const valA = a.brand_dictText || '';
                const valB = b.brand_dictText || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '更新时间',
            align: 'center',
            dataIndex: 'updateTime',
            customRender: function (text) {
                return !text ? '' : text.length > 10 ? text.substr(0, 10) : text;
            },
            sorter: (a, b) => {
                const valA = a.updateTime || '';
                const valB = b.updateTime || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '制单人',
            align: 'center',
            dataIndex: 'creator_dictText',
            sorter: (a, b) => {
                const valA = a.creator_dictText || '';
                const valB = b.creator_dictText || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '制单部门',
            align: 'center',
            dataIndex: 'creatorDeptCode_dictText',
            sorter: (a, b) => {
                const valA = a.creatorDeptCode_dictText || '';
                const valB = b.creatorDeptCode_dictText || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '制单日期',
            align: 'center',
            dataIndex: 'creationDate',
            customRender: function (text) {
                return !text ? '' : text.length > 10 ? text.substr(0, 10) : text;
            },
            sorter: (a, b) => {
                const valA = a.creationDate || '';
                const valB = b.creationDate || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '经办人',
            align: 'center',
            dataIndex: 'createBy_dictText',
            sorter: (a, b) => {
                const valA = a.createBy_dictText || '';
                const valB = b.createBy_dictText || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '经办部门',
            align: 'center',
            dataIndex: 'sysOrgCode_dictText',
            sorter: (a, b) => {
                const valA = a.sysOrgCode_dictText || '';
                const valB = b.sysOrgCode_dictText || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '经办日期',
            align: 'center',
            dataIndex: 'createTime',
            customRender: function (text) {
                return !text ? '' : text.length > 10 ? text.substr(0, 10) : text;
            },
            sorter: (a, b) => {
                const valA = a.createTime || '';
                const valB = b.createTime || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '检验标准',
            align: 'center',
            dataIndex: 'inspectionStandard',
            sorter: (a, b) => {
                const valA = a.inspectionStandard || '';
                const valB = b.inspectionStandard || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '抽检数量',
            align: 'center',
            dataIndex: 'samplingQuantity',
            sorter: (a, b) => {
                const valA = a.samplingQuantity;
                const valB = b.samplingQuantity;
                if (valA == null && valB == null) return 0;
                if (valA == null) return 1;
                if (valB == null) return -1;
                return Number(valA) - Number(valB);
            },
        },
        {
            title: '检验结果',
            align: 'center',
            dataIndex: 'inspectionResult',
            sorter: (a, b) => {
                const valA = a.inspectionResult || '';
                const valB = b.inspectionResult || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '检验人',
            align: 'center',
            dataIndex: 'inspector_dictText',
            sorter: (a, b) => {
                const valA = a.inspector_dictText || '';
                const valB = b.inspector_dictText || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '检验部门',
            align: 'center',
            dataIndex: 'inspectionDeptCode_dictText',
            sorter: (a, b) => {
                const valA = a.inspectionDeptCode_dictText || '';
                const valB = b.inspectionDeptCode_dictText || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '检验日期',
            align: 'center',
            dataIndex: 'inspectionDate',
            customRender: function (text) {
                return !text ? '' : text.length > 10 ? text.substr(0, 10) : text;
            },
            sorter: (a, b) => {
                const valA = a.inspectionDate || '';
                const valB = b.inspectionDate || '';
                return valA.localeCompare(valB, 'en');
            },
        },
        {
            title: '备注',
            align: 'center',
            dataIndex: 'remark',
        },
        {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            width: 80,
            scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/wms/inbound/inbound-record/list',
        delete: '/wms/inbound/inbound-record/delete',
        deleteBatch: '/wms/inbound/inbound-record/deleteBatch',
        exportXlsUrl: '/wms/inbound/inbound-record/exportXls',
        importExcelUrl: 'basic/inboundOrder/importExcel',
        revokeUrl: '/wms/inbound/inbound-record/revoke',
      },
      dictOptions: {},
      superFieldList: [],
      queryParam: {
        warehouseCode: 'W01',
      },
      settingColumns: [],
      procurementType: [1, 2, 3, 4, 13, 14, 15, 16],
    }
  },
  watch: {
    'queryParam.warehouseCode': {
      handler(newVal) {
        if (newVal) {
          this.loadData()
        }
      },
      immediate: true,
    },
  },
  created() {
    this.getSuperFieldList()
  },
  beforeDestroy() {
    // 组件销毁前保存列设置到sessionStorage
    sessionStorage.setItem('inboundRecordListColumns', JSON.stringify(this.settingColumns))
  },
  mounted() {
    // 组件挂载后恢复列设置
    const savedColumns = JSON.parse(sessionStorage.getItem('inboundRecordListColumns'))
    if (savedColumns && savedColumns.length > 0) {
      this.settingColumns = savedColumns
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
    // 添加计算属性，根据settingColumns过滤显示的列
    computedColumns() {
      // 获取所有列的数据索引
      const allColumns = this.columns.map(col => col.dataIndex)
      // 如果设置了自定义列，则过滤显示
      if (this.settingColumns && this.settingColumns.length > 0) {
        return this.columns.filter(col => 
          this.settingColumns.includes(col.dataIndex) || 
          !col.dataIndex || // 保留没有dataIndex的列（如序号列）
          col.dataIndex === 'action' // 保留操作列
        )
      }
      // 默认显示所有列
      return this.columns
    }
  },
  methods: {
    onColSettingsChange(checkedValues) {
      // 存储到localStorage
      sessionStorage.setItem('inboundRecordListColumns', JSON.stringify(checkedValues))
      localStorage.setItem('inboundRecordListColumns', JSON.stringify(checkedValues))
      this.settingColumns = checkedValues
    },
    initDictConfig() {},
    getSuperFieldList() {
      this.superFieldList = []
    },
    handleRevoke(record) {
      this.$confirm({
        title: '确定撤回此记录吗？',
        content: `该操作将撤回单号为 ${record.recordNumber} 的入库记录，是否继续？`,
        onOk: () => {
          const url = `${this.url.revokeUrl}/${record.id}`
          putAction(url).then((res) => {
            if (res.success) {
              this.$message.success('撤销成功')
              this.searchQuery()
            } else {
              this.$message.error(res.message || '撤销失败')
            }
          })
        },
      })
    },
    handlePrint() {
      if (!this.selectValidate()) {
        return
      }
      const { inboundRecordItemId } = this.selectionRows[0]
      this.generateLabelsAndPrint(inboundRecordItemId)
    },
    generateLabelsAndPrint(inboundRecordItemId) {
      if (!inboundRecordItemId) {
        return
      }
      getAction('/wms/inbound/inbound-record/generate-labels-by-record', {
        itemId: inboundRecordItemId,
      }).then((res) => {
        let { result } = res
        if (result && result.length > 0) {
          const ids = result.map((item) => item.id).join("','")
          window.open(`${window._CONFIG['domianURL']}/jmreport/view/1099651769747447808?id=${ids}`, '_blank')
        }
      })
    },
    handleLabelPrint() {
      if (!this.selectValidate()) {
        return
      }
      this.$refs.labelPrintModalForm.print(this.selectionRows[0])
      this.$refs.labelPrintModalForm.title = '标签补打'
    },
    selectValidate() {
      if (!this.selectionRows || this.selectionRows.length === 0) {
        this.$message.warning('请先选中一条记录')
        return false
      }
      if (this.selectionRows.length > 1) {
        this.$message.error('最多只能选择一条记录')
        return false
      }
      return true
    },
    printPreview(record) {
      let id = record.id
      window.open(`${window._CONFIG['domianURL']}/jmreport/view/1099237989787967488?id=${id}`, '_blank')
    },
    handleStoreDetail(record){
      this.$refs.storeModalForm.edit(record)
      this.$refs.storeModalForm.title = '附件查看'
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
